﻿<?php
include "config.php";
mysql_query("set names 'utf8'");

if($_POST["submit"])
{	
$Course_Name = $_POST['Course_Name']; 	
$Course_Description = $_POST['Course_Description']; 
$Price = $_POST['Price']; 
$Address = $_POST['Address']; 
$Amount = $_POST['Amount'];
$Kind = $_POST['Kind'];


  define('UPLOAD_PATH',"../src/commodity/");		  
  $dest_folder   =  "../src/commodity/";  
  $arr=array();  
  $count=0; 
  if(!file_exists($dest_folder)){ 
   mkdir($dest_folder);
  } 
  foreach ($_FILES["pictures"]["error"] as $key => $error) { 
   if ($error == UPLOAD_ERR_OK) { 
    $tmp_name = $_FILES["pictures"]["tmp_name"][$key];  
    $name    = $_FILES["pictures"]["name"][$key];
	  list($tmp,$file_ext) = explode("/",$_FILES['pictures']['type'][$key]);
	   $photo_name = time().rand().".".$file_ext;
    $uploadfile = $dest_folder.$photo_name; 
    move_uploaded_file($tmp_name, $uploadfile);
    $arr[$count]=$photo_name;
  $count=$count+1;
    } 
  } 
  	
		  
		 $sql="INSERT INTO `r_commodity`(commodity_uid,Course_Name,Course_Description,Price,Address,img1,img2,img3,img4,img5,img6,Amount,Kind)VALUES
		 ('','$Course_Name','$Course_Description','$Price','$Address','$arr[0]','$arr[1]','$arr[2]','$arr[3]','$arr[4]','$arr[5]','$Amount','$Kind')";
		 
		 $query=mysql_query($sql);
		 if($query)
		 {
		  echo "添加商品信息成功";
		 }
		 else
		 {
		  echo "添加商品信息失败";
		echo "<a href=javascript:window.history.go(-1)>返回</a>";
		 exit();
		 }
		
		}
 
?>

<form action="" method="post" enctype="multipart/form-data">
  商品名称：
  <input type="text" name="Course_Name" >
  <br>
  商品描述：
  <input type="text" name="Course_Description" >
  <br>
  商品价格：
  <input type="text" name="Price" >
  <br>
  产 地  :
  <input type="text" name="Address" >
  <br>
  余 量  :
  <input type="text" name="Amount" >
  <br>
  种 类  :
  <input type="text" name="Kind" >
  <br>
  商品图片：
  <p>选择上传的图片: </p>
  <input type="file" name="pictures[]" /><br />
   <input type="file" name="pictures[]" /><br />
   <input type="file" name="pictures[]" /><br />
   <input type="file" name="pictures[]" /><br />
   <input type="file" name="pictures[]" /><br />
   <input type="file" name="pictures[]" /><br />
  <br/>
  <p></p>
  <br>
  <input type="submit" name="submit" value="上传"/>
</form>
